<?php

namespace app\member\model;

use app\BaseModel;
use app\member\model\OrderLogModel;
use think\Db;
use think\facade\Cache;


//*------------------------------------------------------ */
//-- 订单表
/*------------------------------------------------------ */

class JiamenModel extends BaseModel
{
    protected $table = 'shop_jiamen';
    public $pk = 'id';
    protected $mkey = 'shop_goods_mkey_';
    public $config = [];

    public function initialize()
    {
        parent::initialize();
        $this->config = config('config.');
    }
    /*------------------------------------------------------ */
    //-- 清除缓存
    /*------------------------------------------------------ */
    public function cleanMemcache($order_id = 0)
    {
        Cache::rm($this->mkey . $order_id);
        Cache::rm($this->mkey . '_goods_' . $order_id);
        if ($this->userInfo['user_id'] > 0) {
            Cache::rm($this->mkey . '_user_stat_' . $this->userInfo['user_id']);
        }
    }

    /*------------------------------------------------------ */
    //-- 写入订单日志
    /*------------------------------------------------------ */
    function _log(&$order, $logInfo = '')
    {
        return OrderLogModel::_log($order, $logInfo);
    }

    /*
     * 查询用户pid 推荐人
     */
    public function getpidUsernameByuid($uid){
        if(empty($uid)){
            return '';
        }
        $res = Db::table('users')->where('user_id',$uid)->find();
        $pidres = Db::table('users')->where('user_id',$res['pid'])->find();
        if($res){
            return $res['pid'].' - '.$pidres['nick_name'];
        }else{
            return '';
        }
    }

    /*
    * 查询用户收益上级id
    */
    public function getproidUsernameByuid($uid){
        if(empty($uid)){
            return '';
        }
        $res = Db::table('users')->where('user_id',$uid)->find();
        $pidres = Db::table('users')->where('user_id',$res['profit_pid'])->find();
        if($res){
            return $res['profit_pid'].' - '.$pidres['nick_name'];
        }else{
            return '';
        }
    }

    /*
    * 查询身份 登记
    */
    public function getUserroleidByuid($uid){
        if(empty($uid)){
            return '';
        }
        $res = Db::table('users')->where('user_id',$uid)->find();
        if($res['role_id'] == 0){
            $shenfenname = '粉丝 | ';
        }else if($res['role_id'] == 1){
            $shenfenname = '代理 | ';
        }else if($res['role_id'] == 2){
            $shenfenname = '经理 | ';
        }else if($res['role_id'] == 3){
            $shenfenname = '会员 | ';
        }else{
            $shenfenname = '';
        }
        if($res['level_id'] == 1){
            $levename = '区县代理';
        }else if($res['level_id'] == 2){
            $levename = '市代理';
        }else if($res['level_id'] == 3){
            $levename = '省代理';
        }else if($res['level_id'] == 4){
            $levename = '街道代理';
        }else{
            $levename = '没有等级';
        }
        if($res){
            return $shenfenname.$levename;
        }else{
            return '';
        }
    }

    /*
     * 查询奖品价格
     */
    public function getPriceByuid($id){
        if(empty($id)){
            return '';
        }
        $res = Db::table('shop_prize_goods')->where('id',$id)->find();
        if($res){
            return $res['price'];
        }else{
            return '';
        }

    }




}
